package com.project.controller;

import com.project.bean.CutPageBean;

import com.project.bean.RoomBean;

import com.project.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("room")
public class RoomController {

    @Autowired
    private RoomService service;

    @RequestMapping("findByItem")
    public CutPageBean<RoomBean> findByItem(Integer pageNO, String address, String state, String type, String live) {
        CutPageBean<RoomBean> bu = service.findByItem(pageNO, address, state, type, live);
        return bu;
    }

    @RequestMapping("del")
    public String del(int id) {
        if (service.del(id)) {
            return "OK";
        }
        return "NO";
    }

    @RequestMapping("findById")
    public RoomBean findById(int id) {
        RoomBean i = service.findById(id);
        if (i != null) {
            return i;
        }
        return null;
    }

    @RequestMapping("add")
    public void add(String address,Integer maxNum,String type) {
        RoomBean roomBean = new RoomBean(address,maxNum,"正常",type);
        service.add(roomBean);
    }

    @RequestMapping("findAllOkRoom")
    public List<RoomBean> findAllOkRoom() {
        return service.findAllOkRoom();
    }

    @RequestMapping("byName")
    public Integer findByName(String name){
        return service.findByName(name).getId();
    }
}
